package com.ibm.psbc.cloud.common.contextcarrier.feign;

import java.util.concurrent.TimeUnit;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cache.CacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.ibm.iisp.common.util.SpringBeanFactory;

import okhttp3.ConnectionPool;
import okhttp3.OkHttpClient;

@ConditionalOnClass(OkHttpClient.class)
@Configuration
public class FeignContextCarrierConfig {
	@Bean
    public OkHttpClient okHttpClient(){
        return new OkHttpClient.Builder()
            .readTimeout(5, TimeUnit.SECONDS) 
            .connectTimeout(5, TimeUnit.SECONDS) 
            .writeTimeout(6, TimeUnit.SECONDS) 
            .connectionPool(new ConnectionPool())
            .addInterceptor(new ContextCarryInterceptor<Object>())
            .build();
    }
	@Bean
	public SpringBeanFactory getSpringBeanFactory() {
		return new SpringBeanFactory();
	}
}
